<?php
class BookDb extends DbCrud {
    protected $table_name = 'book';
    
    public function insertRow($data) {
        if(isset($data['id'])) {
            $data_for_query['id'] = trim($data['id']);
        }
        if(isset($data['name'])) {
            $data_for_query['name'] = trim($data['name']);
        }
        else {
            return false;
        }
        if(isset($data['author'])) {
            $data_for_query['author'] = trim($data['author']);
        }
        if(isset($data['create_time'])) {
            $data_for_query['create_time'] = trim($data['create_time']);
        }
        else {
            return false;
        }
        return $this->db->insertRow($this->table_name,$data_for_query);
    }
    
    public function insertRows($data) {
        $column_name_array = array();
        $data_for_query = array();
        foreach($data as $value) {
            $tmp_data = array();
            if(isset($value['id'])&&is_numeric(trim($value['id']))) {
                $tmp_data['id'] = trim($value['id']);
            }
            if(isset($value['name'])) {
                $tmp_data['name'] = trim($value['name']);
            }
            else {
                return false;
            }
            if(isset($value['author'])) {
                $tmp_data['author'] = trim($value['author']);
            }
            if(isset($value['create_time'])&&is_numeric(trim($value['create_time']))) {
                $tmp_data['create_time'] = trim($value['create_time']);
            }
            else {
                return false;
            }
            $data_for_query[] = $tmp_data;
        }
        return $this->db->insertRows($this->table_name,$data_for_query);
    }
    
    public function update($where,$data) {
        if(isset($data['id'])&&is_numeric(trim($data['id']))) {
            $data_for_query['id'] = trim($data['id']);
        }
        if(isset($data['name'])) {
            $data_for_query['name'] = trim($data['name']);
        }
        if(isset($data['author'])) {
            $data_for_query['author'] = trim($data['author']);
        }
        if(isset($data['create_time'])&&is_numeric(trim($data['create_time']))) {
            $data_for_query['create_time'] = trim($data['create_time']);
        }
        if(empty($data_for_query)) {            return true;        }        return $this->db->update($this->table_name,$where,$data_for_query);
    }
}
?>